link: markdown content

---- start of layout ----

Note Layout Title

Routes setup

Let’s break down how these two lines work together:

// in employeeRoutes.js
router.get("/", getAllEmployees);

// in app.js
app.use("/api/employees", employeeRoutes);

The Flow of an API Request

  1. Base URL Registration (app.js)

  2. Route Handler (employeeRoutes.js)

Examples

When a GET request is made to http://localhost:5000/api/employees/:

  1. Express first matches the base path “/api/employees” in app.js
  2. The request is forwarded to employeeRoutes
  3. Inside employeeRoutes.js, the ”/” route matches
  4. The getAllEmployees controller function is executed

When a POST request is made to http://localhost:5000/api/employees/

  1. Express first matches the base path “/api/employees” in app.js
  2. The request is forwarded to employeeRoutes
  3. Inside employeeRoutes.js, the ”/” route matches
  4. The createEmployee controller function is executed

This modular approach allows for:

Now is all we truly have

---- End of layout ----